package com.wms.entity;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;
import java.util.Map;

public class MyPage<T> extends Page<T> {

    private Map<String, Object> condition;


    public Map<String, Object> getCondition(){
        if (condition == null){
            condition = new HashMap<String, Object>();
        }
        return condition;
    }

    public long getOffset(){
        return offset();
    }

    public String getOrderByClause(){
        if (getOrders().isEmpty()) return null;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < getOrders().size(); i++){
            OrderItem item = getOrders().get(i);
            if (i > 0){
                builder.append(",");
            }
            if (item.isAsc()){
                builder.append(item.getColumn());
            } else {
                builder.append(item.getColumn() + " desc");
            }
        }
        return builder.toString();
    }




}
